package com.wkbb.sports.controller;

import com.wkbb.common.constants.ErrorCode;
import com.wkbb.common.constants.VersionConstant;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.common.dto.basic.GradeDto;
import com.wkbb.common.dto.basic.GradeTreeDto;
import com.wkbb.sports.dto.AchievementDto;
import com.wkbb.sports.dto.DictDto;
import com.wkbb.sports.feign.BasicFeignService;
import com.wkbb.sports.service.DictService;
import com.wkbb.sports.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(description = "报告统计接口")
@RequestMapping("/sports/{apiVersion}/report")
@Slf4j
public class ReportController {

    @Autowired
    private ReportService reportService;

    @ApiOperation(value = "用户个人健康报告")
    @RequestMapping(value = "/getUserHlifeReport", method = RequestMethod.GET)
    public ResultDTO<Map<String,Object>> getUserHlifeReport(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织ID", required = true) @RequestParam(name = "orgId", required = true) Long orgId,
            @ApiParam(value = "考期ID", required = false) @RequestParam(name = "termId", required = false) Long termId,
            @ApiParam(value = "用户ID", required = false) @RequestParam(name = "userId", required = false) Long userId)
    {
        log.info("getUserHlifeReport orgId:{} termId:{} userId:{}",orgId,termId,userId);

        try {

            if(null==orgId)
            {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            Map<String,Object> map = reportService.getUserHlifeReport(orgId,termId,userId);

            return new ResultDTO<Map<String,Object>>(map);

        } catch (Exception e) {
            log.error("***********getUserHlifeReport******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }
}